<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:include="~{common/header :: commonHead}">
    <title>修改库存</title>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5 th:text="${null == editable ? '新增团购商品' : '修改库存'}"></h5>
                    <div class="ibox-tools">
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="row form-body form-horizontal m-t" method="post" th:action="${editable == null? '/group_buy/add':'/group_buy/edit_inventory'}" >
                        <input name="id" th:value="${editable?.groupBuyingId}" style="display: none">
                        <div class="col-md-12 droppable sortable ui-droppable ui-sortable">

                            <div class="form-group draggable ui-draggable dropped" style="position: static;">
                                <label class="col-sm-3 control-label"><span style="color: red;">* </span>团购商品名称：</label>
                                <div class="col-sm-6">
                                    <input type="text" name="shoppingKillName" th:value="${editable?.groupBuyingName }"
                                           class="form-control" readonly>
                                </div>
                            </div>

                            <div class="form-group draggable ui-draggable dropped" style="position: static;">
                                <label class="col-sm-3 control-label"><span style="color: red;">* </span>团购时间：</label>
                                <div class="col-sm-3">
                                    <div class="input-group date">
                                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                        <input type="text" class="form-control" th:value="${editable?.startTime}"
                                               readonly placeholder="团购开始时间"
                                               id="show_start_time" name="startTime" >
                                    </div>
                                </div>
                                <div class="col-sm-3">
                                    <div class="input-group date">
                                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                        <input type="text" class="form-control" th:value="${editable?.endTime}"
                                               readonly placeholder="团购结束时间"
                                               id="show_end_time" name="endTime">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group draggable ui-draggable dropped" style="position: static;">
                                <label class="col-sm-3 control-label"><span style="color: red;">* </span>上传商品封面：</label>
                                <div class="col-sm-6">
                                    <div id="add_icons" class="add_icons">
                                        <div class="add_icon_pan">
                                            <input name="upload_pic"
                                                   id="upload_pic" type="file"
                                                   accept="image/*"
                                                   control_id="control_id"
                                                   image_id="image_id"
                                                   class="upload_pic_input" style="">
                                            <img id="uploaded_pic"
                                                 th:class="${editable?.coverUrl != null ? '' : 'hide' }"
                                                 th:src="${editable?.coverUrl != null ? editable.coverUrl : ''}"/>
                                            <div th:class="'mark ' + ${editable?.coverUrl != null ? '' : 'hide' }">
                                                <div class="close_icon_button"
                                                     control_id="coverUrl"></div>
                                            </div>
                                            <label for="upload_pic"
                                                   th:class="'add_icon_button ' + ${editable?.coverUrl != null ? 'hide' : ''}"></label>
                                        </div>
                                    </div>
                                    <label class="help-block">像素比例 宽 x 高 = 50 x 50</label>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-2 col-md-4 col-sm-12 control-label" for="control_id"></label>
                                <div class="col-lg-4 col-md-8 ">
                                    <input class="form-control" id="control_id" name="coverUrl" type="text" th:value="${editable?.coverUrl}" style="display: none;">
                                </div>
                            </div>

                            <div class="form-group draggable ui-draggable dropped" style="position: static;">
                                <label class="col-sm-3 control-label"><span style="color: red;">* </span>团购商品介绍：</label>
                                <div class="col-sm-6">
                                    <textarea class="myEditor" name="content" th:text="${editable?.content }"
                                              placeholder="请输入团购商品介绍"
                                              style="height: 100px" required="required" disabled="disabled"></textarea>
                                </div>
                            </div>

<!--                            <div  class="form-group draggable ui-draggable dropped" style="position: static;">-->
<!--                                <label class="col-sm-3 control-label"><span style="color: red;">* </span>抢购次数是否限制：</label>-->
<!--                                <div class="col-sm-6">-->
<!--                                    <div class="radio radio-info radio-inline">-->
<!--                                        <input type="radio"  id="inlineRadio3" name="statusNumLimit" value="1" th:checked="${editable?.statusNumLimit == 1}">-->
<!--                                        <label for="inlineRadio3"><span style="color: red;">* </span>是 </label>-->
<!--                                    </div>-->
<!--                                    <div class="radio radio-danger radio-inline">-->
<!--                                        <input type="radio"  id="inlineRadio4" name="statusNumLimit" value="0" th:checked="${editable?.statusNumLimit == 0}">-->
<!--                                        <label for="inlineRadio4"><span style="color: red;">* </span>否 </label>-->
<!--                                    </div>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div  class="form-group draggable ui-draggable dropped" id="shopKillTimes"  th:style="${'position: static; display:' + (editable?.statusNumLimit == 1 ? 'block' : 'none')}" >-->
<!--                                <label class="col-sm-3 control-label"><span style="color: red;">* </span>团购限制次数：</label>-->
<!--                                <div class="col-sm-6">-->
<!--                                    <input id="shopKillTime" type="text" name="shopKillTimes" class="form-control"-->
<!--                                            th:value="${editable?.shopKillTimes }" placeholder="请输入团购限制次数">-->
<!--                                </div>-->
<!--                            </div>-->

<!--                            <div  class="form-group draggable ui-draggable dropped" id="statusDaily" style="position: static;">-->
<!--                                <label class="col-sm-3 control-label"><span style="color: red;">* </span>每日抢购次数是否限制：</label>-->
<!--                                <div class="col-sm-6">-->

<!--                                    <div class="radio radio-info radio-inline">-->
<!--                                        <input type="radio"  id="inlineRadio5" name="statusDaily" value="1" th:checked="${editable?.statusDaily == 1}">-->
<!--                                        <label for="inlineRadio5"><span style="color: red;">* </span>是 </label>-->
<!--                                    </div>-->
<!--                                    <div class="radio radio-danger radio-inline">-->
<!--                                        <input type="radio"  id="inlineRadio6" name="statusDaily" value="0" th:checked="${editable?.statusDaily == 0}">-->
<!--                                        <label for="inlineRadio6"><span style="color: red;">* </span>否 </label>-->
<!--                                    </div>-->
<!--                                </div>-->
<!--                            </div>-->

<!--                            <div th:if="${editable?.payType == null}" class="form-group draggable ui-draggable dropped" style="position: static;">-->
<!--                                <label class="col-sm-3 control-label"><span style="color: red;">* </span>团购商品支付方式：</label>-->
<!--                                <div class="col-sm-6">-->

<!--                                    <div class="radio radio-info radio-inline">-->
<!--                                        <input type="radio"  id="inlineRadio1" name="payType" value="integral" th:checked="${editable?.payType == 'integral'}" readonly>-->
<!--                                        <label for="inlineRadio1"><span style="color: red;">* </span>积分 </label>-->
<!--                                    </div>-->
<!--                                    <div class="radio radio-danger radio-inline">-->
<!--                                        <input type="radio"  id="inlineRadio2" name="payType" value="money" th:checked="${editable?.payType == 'money'}" readonly>-->
<!--                                        <label for="inlineRadio2"><span style="color: red;">* </span>现金 </label>-->
<!--                                    </div>-->
<!--                                </div>-->
<!--                            </div>-->
                            <div  class="form-group draggable ui-draggable dropped" id="originalPrice"  th:style="${'position: static; display:' + (editable?.payType == 'money' ? 'block' : 'none')}" >
                                <label class="col-sm-3 control-label"><span style="color: red;">* </span>原价：</label>
                                <div class="col-sm-6">
                                    <input  type="text" name="originalPrice" class="form-control"
                                            th:value="${editable?.originalPrice }" placeholder="请输入金额" readonly>
                                </div>
                            </div>


                            <div  class="form-group draggable ui-draggable dropped"  id="price" th:style="${'position: static; display:' + (editable?.payType == 'money' ? 'block' : 'none')}" >
                                <label class="col-sm-3 control-label"><span style="color: red;">* </span>团购价：</label>
                                <div class="col-sm-6">
                                    <input onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" type="text" name="price" class="form-control" th:value="${editable?.price}"
                                           placeholder="请输入金额" readonly>
                                </div>
                            </div>
                            <div  class="form-group draggable ui-draggable dropped" id="originalIntegral" th:style="${'position: static; display:' + (editable?.payType == 'integral' ? 'block' : 'none')}">
                                <label class="col-sm-3 control-label"><span style="color: red;">* </span>原价（积分）：</label>
                                <div class="col-sm-6">
                                    <input onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" type="text" name="originalIntegral" class="form-control"
                                           th:value="${editable?.originalIntegral }" placeholder="请输入积分值" readonly>
                                </div>
                            </div>


                            <div  class="form-group draggable ui-draggable dropped" id="integral" th:style="${'position: static; display:' + (editable?.payType == 'integral' ? 'block' : 'none')}">
                                <label class="col-sm-3 control-label"><span style="color: red;">* </span>团购价（积分）：</label>
                                <div class="col-sm-6">
                                    <input onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" type="text" name="integral" class="form-control" th:value="${editable?.integral}"
                                           placeholder="请输入积分值" readonly>
                                </div>
                            </div>

                            <div  class="form-group draggable ui-draggable dropped" style="position: static;">
                                <label class="col-sm-3 control-label"><span style="color: red;">* </span>团购商品类型：</label>
                                <div class="col-sm-6">
                                    <select class="form-control" id="usetimetype-selector" name="goodsType"
                                            required="required" disabled="disabled">
                                        <option value="">请选择</option>
                                        <option th:selected="${editable?.goodsType == 'coupon'}" value="coupon">优惠券
                                        </option>

                                    </select>
                                </div>

                            </div>

                            <div th:if="${editable?.goodsId == null}" class="form-group draggable ui-draggable dropped"
                                 th:style="${'position: static; display:' + (editable?.goodsType == 'coupon' ? 'block' : 'none')}"
                                 id="total-input-hour">
                                <label class="col-sm-3 control-label"><span style="color: red;">* </span>请选择优惠券：</label>
                                <div class="col-sm-6">
                                    <div class="col-sm-6" id="coupon-selector">
                                        <select  name="shoppingKillGoods"
                                                 data-placeholder="请选择赠送优惠券..."
                                                 onchange="notice(this.value);"
                                                 class="chosen-select form-control m-b" tabindex="1" disabled="disabled">
                                            <option value="" th:selected="${editable?.goodsId == null}">--请选择(注：此处显示为已下架优惠券)--
                                            </option>
                                            <option class="id_option" hassubinfo="true"
                                                    th:each="couponDTO:${couponDTOS}"
                                                    th:selected="${editable?.goodsId == couponDTO.id}"
                                                    th:value="${couponDTO.id }"
                                                    th:text="${couponDTO.name}"></option>
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div  class="form-group draggable ui-draggable dropped" style="position: static;">
                                <label class="col-sm-3 control-label"><span style="color: red;">* </span>团购商品库存：</label>
                                <div class="col-sm-6">

                                    <input type="text" onkeyup="value=value.replace(/^0(0+)|[^\d]+/g,'')" name="inventory" class="form-control"
                                           th:value="${editable?.inventory}" placeholder="请输入团购商品库存（团购库存请勿超过可用库存）">
                                </div>
                            </div>



                            <!--<div class="form-group draggable ui-draggable dropped" style="position: static;">
                                <label class="col-sm-3 control-label">使用规则：</label>
                                <div class="col-sm-6">
                                    <input type="text" name="useRule" class="form-control" placeholder="请输入使用规则" th:value="${editable?.useRule}">
                                </div>
                            </div>-->


                            <div class="hr-line-dashed"></div>

                            <div class="form-group draggable ui-draggable">
                                <div class="col-sm-12 col-sm-offset-3">
                                    <button class="btn btn-primary" type="submit">保存内容</button>
                                </div>
                            </div>

                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $("input[name=endtime]").datepicker({});


    $("#usetimetype-selector").change(function () {
        let selection = $(this).val();

        if (selection == "coupon") {
            $("#total-input-hour").css('display', 'block');


        }


        if (selection == '') {
            $("#total-input-hour").css('display', 'none');
        }
    });

    function notice(val) {

        $(".stock-warning").remove();

        $.get("getInventory?couponId="+val, function (res) {
            if (res.resCode == 0) {
                $("#coupon-selector").after('<span class="stock-warning" style="color: gray">优惠券名称:' + res.data.name + '</span>' + '<span class="stock-warning" style="color: gray"> 当前可用库存:' + res.data.remainTotal + '</span>');
            }
            else {
                $("#tcoupon-selector").after('<span class="stock-warning">优惠券不存在</span>');
            }
        });
    }

    $("input[name=payType]").change(function () {
        let selection = $(this).val();
        if (selection == 'money') {
            $("#price").css('display','block');
            $("#originalPrice").css('display','block');
            $("#integral").css('display','none');
            $("#originalIntegral").css('display','none');
        }
        if (selection == ''||selection == 'integral') {
            $("#integral").css('display','block');
            $("#originalIntegral").css('display','block');
            $("#price").css('display','none');
            $("#originalPrice").css('display','none');
        }
    })

    $("input[name=statusNumLimit]").change(function () {
        let selection = $(this).val();
        if (selection == 1) {
            $("#shopKillTimes").css('display','block');
            $("#shopKillTime").attr('required','required');
            $("#statusDaily").css('display','block')
        }
        if (selection == 0||selection==''){
            $("#shopKillTimes").css('display','none');
            $("#statusDaily").css('display','none');

        }
    })

</script>
</body>
</html>